home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Mac Mania 5
/
MacMania 5.toast
/
/
Internet software
/
NewsWatcher
/
NW Source
/
Source
/
olddrag.c
< prev
next >
Wrap
Text File
|
1997-01-09
|
8KB
|
287 lines
/*----------------------------------------------------------------------------
olddrag.c
This module handles drag and drop when the Drag Manager is not
available.
Copyright © 1994-1997, Northwestern University.
----------------------------------------------------------------------------*/
#include <stdio.h>
#include "glob.h"
#include "olddrag.h"
#include "subscribe.h"
#include "windutil.h"
#include "biglist.h"
#include "wind.h"
static BigListRef gTargetList; /* list ref for current target list
containing item dividing line, or
nil if none. */
static long gTargetItem; /* item number of item following current
item dividing line, or -1 if none */
/*----------------------------------------------------------------------------
OldWaitMouseMoved
A version of the Drag Manager function "WaitMouseMoved" for when
we do not have the Drag Manager.
Entry: where = mouse location in global coordinates.
Exit: function result = true if mouse moved.
----------------------------------------------------------------------------*/
static Boolean OldWaitMouseMoved (Point where)
{
Rect r;
SetRect(&r, where.h-3, where.v-3, where.h+3, where.v+3);
while (StillDown()) {
GetMouse(&where);
LocalToGlobal(&where);
if (!PtInRect(where, &r)) return true;
}
return false;
}
/*----------------------------------------------------------------------------
HilightTarget
Hilight a drag target list when we do not have the Drag Manager.
Entry: groupDrag = true if we're dragging groups, false if we're
dragging subject in the extract binaries manually dialog.
srcList = list ref for the list where the drag was started.
where = current mouse location in global coordinates.
fullPort = pointer to grafport for drawing drag region.
dragRgn = handle to drag region.
----------------------------------------------------------------------------*/
static void HilightTarget (Boolean groupDrag, BigListRef srcList, Point where,
GrafPtr fullPort, RgnHandle dragRgn)
{
WindowPtr srcWind, destWind;
TWindow **srcInfo, **destInfo;
BigListRef targetList;
long targetItem;
GrafPtr port;
Rect rView, contentRect;
long scrollDelta, visTop, visBottom, numItems;
GetPort(&port);
targetList = nil;
targetItem = -1;
srcWind = BigLGetWindow(srcList);
FindWindow(where, &destWind);
if (destWind != nil) {
if (groupDrag) {
srcInfo = (TWindow**)GetWRefCon(srcWind);
if (GetMyWindowKind(destWind) == kGroup) {
destInfo = (TWindow**)GetWRefCon(destWind);
if ((**srcInfo).groupKind == kUserGroup) {
if (destWind == srcWind) {
targetList = srcList;
}
} else {
if ((**destInfo).groupKind == kUserGroup) {
targetList = (**destInfo).groupList;
}
}
}
} else {
if (destWind == srcWind) {
targetList = srcList;
}
}
if (targetList != nil) {
BigLGetViewRect(targetList, &rView);
SetRect(&contentRect, rView.left, 0, rView.right-15, rView.bottom+15);
SetPort(destWind);
GlobalToLocal(&where);
if (PtInRect(where, &contentRect)) {
scrollDelta = 0;
BigLGetVisibleItems(targetList, &visTop, &visBottom);
numItems = BigLGetNumItems(targetList);
if (where.v < rView.top && visTop > 0) {
scrollDelta = -1;
} else if (where.v >= rView.bottom && visBottom < numItems-1) {
scrollDelta = +1;
}
if (scrollDelta != 0) {
if (gTargetList != nil && gTargetItem != -1) {
BigLDrawItemDividingLine(gTargetList, gTargetItem);
gTargetList = nil;
gTargetItem = -1;
}
SetPort(fullPort);
FrameRgn(dragRgn);
BigLScroll(targetList, scrollDelta);
FrameRgn(dragRgn);
SetPort(destWind);
}
targetItem = BigLGetDividingLineGivenPoint(targetList, where);
}
}
}
if (targetList != gTargetList || targetItem != gTargetItem) {
if (gTargetList != nil && gTargetItem != -1) {
BigLDrawItemDividingLine(gTargetList, gTargetItem);
}
if (targetList != nil && targetItem != -1) {
BigLDrawItemDividingLine(targetList, targetItem);
}
gTargetList = targetList;
gTargetItem = targetItem;
}
SetPort(port);
}
/*----------------------------------------------------------------------------
OldTrackDrag
Track a drag when we do not have the Drag Manager.
Entry: groupDrag = true if we're dragging groups, false if we're
dragging subject in the extract binaries manually dialog.
theList = list ref.
----------------------------------------------------------------------------*/
static void OldTrackDrag (Boolean groupDrag, BigListRef theList)
{
RgnHandle dragRgn = nil;
Point prevPt, curPt;
GrafPtr port;
GrafPort fullPort;
GetPort(&port);
BigLBuildSelectedItemsDragRegion(theList, &dragRgn);
GetMouse(&curPt);
LocalToGlobal(&curPt);
OpenPort(&fullPort);
CopyRgn(GetGrayRgn(), fullPort.visRgn);
fullPort.portRect = (**GetGrayRgn()).rgnBBox;
PenPat(&qd.gray);
PenMode(patXor);
FrameRgn(dragRgn);
prevPt = curPt;
gTargetList = nil;
gTargetItem = -1;
while (StillDown()) {
GetMouse(&curPt);
LocalToGlobal(&curPt);
if (!EqualPt(curPt, prevPt)) {
FrameRgn(dragRgn);
OffsetRgn(dragRgn, curPt.h - prevPt.h, curPt.v - prevPt.v);
FrameRgn(dragRgn);
prevPt = curPt;
}
HilightTarget(groupDrag, theList, curPt, &fullPort, dragRgn);
}
if (gTargetList != nil && gTargetItem != -1) {
BigLDrawItemDividingLine(gTargetList, gTargetItem);
}
FrameRgn(dragRgn);
DisposeRgn(dragRgn);
ClosePort(&fullPort);
SetPort(port);
}
/*----------------------------------------------------------------------------
OldGroupListClickLoop
The click loop function for group lists when we do not have the
Drag Manager. It initiates group drags.
Entry: theList = list ref.
where = mouse location, in local coords.
modifiers = modifiers field from event record.
helperItem =
for shift-click, the item number of the item at the
other end of the selection range from the initially
clicked item (the "anchor" item for a shift-drag).
otherwise, the item number of the initially clicked item.
Exit: function result = error code.
----------------------------------------------------------------------------*/
OSErr OldGroupListClickLoop (BigListRef theList, Point where,
short modifiers, long helperItem)
{
WindowPtr srcWind;
TWindow **srcInfo;
if ((modifiers & shiftKey) != 0 || (modifiers & cmdKey) != 0) {
return BigLDefaultClickLoop(theList, where, modifiers, helperItem);
}
LocalToGlobal(&where);
if (OldWaitMouseMoved(where)) {
OldTrackDrag(true, theList);
if (gTargetItem >= 0) {
srcWind = BigLGetWindow(theList);
srcInfo = (TWindow**)GetWRefCon(srcWind);
if ((**srcInfo).groupKind == kUserGroup) {
BigLMoveSelectedItems(theList, theList, gTargetItem, nil);
} else {
CopyOrMoveSelectedGroups(srcWind,
BigLGetWindow(gTargetList),
gTargetItem,
true);
}
}
}
return noErr;
}
/*----------------------------------------------------------------------------
OldExtractBinariesManuallyClickLoop
The click loop function for the list in the extract binaries manually
dialog when we do not have the Drag Manager. It initiates item drags.
Entry: theList = list ref.
where = mouse location, in local coords.
modifiers = modifiers field from event record.
helperItem =
for shift-click, the item number of the item at the
other end of the selection range from the initially
clicked item (the "anchor" item for a shift-drag).
otherwise, the item number of the initially clicked item.
Exit: function result = error code.
----------------------------------------------------------------------------*/
OSErr OldExtractBinariesManuallyClickLoop (BigListRef theList, Point where,
short modifiers, long helperItem)
{
if ((modifiers & shiftKey) != 0 || (modifiers & cmdKey) != 0) {
return BigLDefaultClickLoop(theList, where, modifiers, helperItem);
}
LocalToGlobal(&where);
if (OldWaitMouseMoved(where)) {
OldTrackDrag(false, theList);
if (gTargetItem >= 0) {
BigLMoveSelectedItems(theList, theList, gTargetItem, nil);
}
}
return noErr;
}